package com.qys.livesMall.navy.service.impl;

import com.qys.livesMall.framework.view.QysPage;
import com.qys.livesMall.navy.common.Constant;
import com.qys.livesMall.navy.dao.NavyTaskDao;
import com.qys.livesMall.navy.dao.NavyTaskDetailDao;
import com.qys.livesMall.navy.model.dto.task.NavyTaskSearch;
import com.qys.livesMall.navy.model.entity.NavyTask;
import com.qys.livesMall.navy.mapper.NavyTaskMapper;
import com.qys.livesMall.navy.service.NavyTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 水军任务表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-07-11
 */
@Service
public class NavyTaskServiceImpl implements NavyTaskService {

    @Autowired
    private NavyTaskDao navyTaskDao;

    @Autowired
    private NavyTaskDetailDao navyTaskDetailDao;

    @Override
    public void save(NavyTask task){
        navyTaskDao.save(task);
    }

    @Override
    public boolean watchTaskEnd(Long taskId) {
        boolean status=navyTaskDetailDao.existNoEnd(taskId);
        boolean end=false;
        if (!status){
            NavyTask task=navyTaskDao.getById(taskId);
            task.setTaskStatus(Constant.TaskStatus.END);
            task.setTaskEndTime(LocalDateTime.now());
            task.setUpdDate(LocalDateTime.now());
            navyTaskDao.updateById(task);
            end=true;
        }
        return end;
    }

    @Override
    public List<NavyTask> listNoEnd() {
        return navyTaskDao.listNoEnd();
    }

    @Override
    public QysPage<NavyTask> search(NavyTaskSearch search) {
        return null;
    }
}
